package com.example.mybatis_plus.mapper;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.toolkit.Constants;
import com.example.mybatis_plus.model.UserInfo;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: Li_yizYa
 * Date: 2025/7/18
 * Time: 18:22
 */
@Mapper
public interface UserInfoMapper extends BaseMapper<UserInfo> {

//    @Select("select id, username, password, age from user_info where username=#{name}")

    /**
     * Mybatis-plus 方式自定义 sql
     * @param wrapper
     * @return
     */
    @Select("select id, username, password, age from user_info ${ew.customSqlSegment}")
    List<UserInfo> selectByCustom(@Param(Constants.WRAPPER) Wrapper<UserInfo> wrapper);

    /**
     * Mybatis-plus xml 方式
     * @param wrapper
     * @return
     */
    List<UserInfo> selectByCustom2(@Param(Constants.WRAPPER) Wrapper<UserInfo> wrapper);

    /**
     * update user_info set age=age+10 where id in (1, 2, 3)
     * @return
     */
    @Update("update user_info set age=age + ${age} ${ew.customSqlSegment}")
    Integer updateByCustom(@Param("age") Integer age, @Param(Constants.WRAPPER) Wrapper<UserInfo> wrapper);
}
